﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MikuMikuLibrary.Databases;
using MikuMikuLibrary.IO;
using ft_module_parser;

namespace DatabaseConverter
{
    class StageFix
    {
        public StageDatabase db = new StageDatabase();
        public ObjectDatabase db_ac = new ObjectDatabase();
        public a3ds a3d = new a3ds();
        public string logs = "";
        public void MergeAet()
        {
            a3d.load("path");

            foreach (var stage in db.Stages)
            {
                var find = db_ac.Objects.Where(i => i.Name == stage.Name).FirstOrDefault();
                if (find != null)
                {
                    if (stage.ObjectId1 != find.Id)
                    {
                        logs = logs + "Fix " + stage.ObjectId1 + " to " + find.Id + "\n";
                    }
                    stage.ObjectId1 = (short)find.Id;

                    if (stage.ObjectGroundIdFlag > 0)
                    stage.ObjectGroundIdFlag = (short)find.Id;
                    /*
                    if (stage.Name.Contains("STGPV"))
                    {
                        //add effchr
                        int pvid = int.Parse(stage.Name.Substring(5, 3));
                        var check1 = a3d.ft_mdata_uid.Where(i => i.value.Contains("A EFFCHRPV")).Where(i => int.Parse(i.value.Substring(10,3)) == pvid);
                        if (check1 != null)
                        {
                            foreach (var k in check1)
                            {
                                stage.Auth3dIds.Add(k.id);
                                logs = logs + "ADD EFFCHR " + pvid + ":" + k.id + "\n";
                            }
                            
                        }
                    }
                    */
                }
            }
        }
    }
}
